﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using CreditAgricole.Framework;

namespace CreditAgricole.CommonElements.Layouts.CreditAgricole.CommonElements.ProductionDeployment
{
    public partial class CACustomEditForm : WebPartPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SPListItem li = SPContext.Current.ListItem;
                if (li != null)
                {
                    // Check if workflow status is "In Progress" (value = 2).
                    // In this case, the document properties cannot be edited.
                    try
                    {
                        Guid StatusFieldId = SPHelper.GetWorkflowStatusFieldId(li);

                        if ((StatusFieldId != Guid.Empty) && ((string)li[StatusFieldId] == "2"))
                        {
                            // Hide edit webpart
                            Main.Visible = false;

                            // Display custom message
                            CustomMessage.Visible = true;
                        }
                    }
                    catch { /* Silently continue if the workflow status is not present in the list (possible at first item adding) */ }
                }
            }
        }
    }
}
